package com.asia5b.a5mall.middleware.bind

import android.view.View
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.asia5b.a5mall.middleware.model.shop.AbsGoodsModel
import com.asia5b.a5mall.middleware.utils.CurrencyPriceBuilder3
import com.asia5b.a5mall.middleware.utils.startGoodsDetailActivity
import com.asia5b.a5mall.middleware.utils.startShopActivity
import com.jakewharton.rxbinding3.view.clicks
import java.util.concurrent.TimeUnit

/**
 * Created by zhangyuncai on 2020/8/28.
 *  * @Note   todo databinding辅助类 负责商品的点击事件
 */
object GoodsBindingHelper {

    /**
     * 跳转商品详情
     */
    @BindingAdapter(value = arrayOf("bind:goodsId"), requireAll = false)
    @JvmStatic
    fun startGoodsDetail(view: View, goodsId: Int) {
        view.clicks()
                .throttleFirst(1, TimeUnit.SECONDS)
                .subscribe { startGoodsDetailActivity(view.context, goodsId) }

    }

    /**
     * 跳转店铺详情
     */
    @BindingAdapter(value = arrayOf("bind:shopId"), requireAll = false)
    @JvmStatic
    fun startShop(view: View, shopId: Int) {
        view.clicks()
                .throttleFirst(1, TimeUnit.SECONDS)
                .subscribe { startShopActivity(view.context, shopId) }

    }

    @BindingAdapter(value = arrayOf("bind:goodsPrice"), requireAll = false)
    @JvmStatic
    fun setGoodsPrice(textView: TextView, item: AbsGoodsModel) {
        //价格
        CurrencyPriceBuilder3().run {
            this.textView = textView
            price = item.absGoodsPrice
            priceList = item.absGoodsPriceList
            build14_18()
        }

    }

    @BindingAdapter(value = arrayOf("bind:goodsPrice2"), requireAll = false)
    @JvmStatic
    fun setGoodsPrice2(textView: TextView, item: AbsGoodsModel) {
        //价格
        CurrencyPriceBuilder3().run {
            this.textView = textView
            price = item.absGoodsPrice
            priceList = item.absGoodsPriceList
            build14_18_2()
        }

    }
}